package com.example.assetmanagement.service.impl;

import com.example.assetmanagement.mapper.DashboardMapper;
import com.example.assetmanagement.service.DashboardService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class DashboardServiceImpl implements DashboardService {

    private final DashboardMapper mapper;

    @Override
    public Map<String, Object> getData() {
        return mapper.overall();
    }

    @Override
    public List<Map<String, Object>> getAssetStats() {
        return mapper.assetStats();
    }

    @Override
    public List<Map<String, Object>> getMaintenanceStats() {
        return mapper.maintenanceStats();
    }

    @Override
    public List<Map<String, Object>> getTrend(String startDate, String endDate) {
        if ((startDate == null || startDate.isEmpty()) && (endDate == null || endDate.isEmpty())) {
            // 仅设置开始日期为3年前，不限制结束日期，保证数据始终能查到
            LocalDate start = LocalDate.now().minusYears(3);
            startDate = start.toString();
            endDate = null;
        }
        return mapper.trend(startDate, endDate);
    }
} 